package github.kawaiior.yuanchuxiuzhen.common.item.weapon;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import github.kawaiior.yuanchuxiuzhen.core.init.itemgroup.YcxzGroup;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.List;

public class ManaStoneSpear extends Item {

    private int level = 1;

    public ManaStoneSpear() {
        super(new Properties().group(YcxzGroup.YCXZ_GROUP)
                .maxStackSize(1).maxDamage(0).defaultMaxDamage(0));
    }

    public ManaStoneSpear(int level) {
        super(new Properties().group(YcxzGroup.YCXZ_GROUP)
                .maxStackSize(1).maxDamage(0).defaultMaxDamage(0));
        this.level = level;
    }

    @Override
    public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType equipmentSlot) {
        Multimap<Attribute, AttributeModifier> modifiers = ArrayListMultimap.create();
        if (equipmentSlot == EquipmentSlotType.MAINHAND) {
            modifiers.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", getAttackDamage(), AttributeModifier.Operation.ADDITION));
            modifiers.put(Attributes.ATTACK_SPEED, new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", getAttackSpeed(), AttributeModifier.Operation.ADDITION));
        }
        return modifiers;
    }

    private float getAttackDamage(){
        return 9F + (this.level-1)*10;
    }

    private float getAttackSpeed(){
        return -1.2F;
    }

    @Override
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
        tooltip.add(new StringTextComponent("level: "+this.level));
    }

}
